package design.graduation.novelwebsite.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import design.graduation.novelwebsite.constant.Constant;
import design.graduation.novelwebsite.mapper.IncludeBookMapper;
import design.graduation.novelwebsite.model.dto.ResultObj;
import design.graduation.novelwebsite.model.entity.IncludeBook;
import design.graduation.novelwebsite.service.IncludeBookService;
import org.springframework.stereotype.Service;

/**
 * @author: 洪少尉
 * @Date: 2020/4/20 15:00
 * @Description: 
 */
@Service
public class IncludeBookServiceImpl extends ServiceImpl<IncludeBookMapper, IncludeBook> implements IncludeBookService{

	/**
	 * 根据分类id 查询 小说
	 *
	 * @param includeBook 查询分类id
	 * @return ResultObj
	 */
	@Override
	public ResultObj queryBooksByPrimaryClassification(IncludeBook includeBook) {
		QueryWrapper<IncludeBook> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq(IncludeBook.COL_PRIMARY_CLASSIFICATION,includeBook.getPrimaryClassification())
				.eq(IncludeBook.COL_STATUS, Constant.STATUS_TRUE)
				.orderByDesc(IncludeBook.COL_CREATE_TIME)
				.last("limit 8");
		return new ResultObj(this.list(queryWrapper));
	}

	/**
	 * 月头清除月点击数
	 */
	@Override
	public void clearMonthlyClick() {
		UpdateWrapper<IncludeBook> updateWrapper = new UpdateWrapper<>();
		updateWrapper.set(IncludeBook.COL_MONTH_CLICKS,Constant.INITIALIZATION);
		this.update(updateWrapper);
	}
}
